//
//  YQStatusCell.m
//  WeiboOC
//
//  Created by yang on 15/11/19.
//  Copyright © 2015年 yang. All rights reserved.
//

#import "YQStatusCell.h"
#import "YQStatus.h"
@interface YQStatusCell()
@property (nonatomic, strong) YQStatusOriginalView *originalView;
@property (nonatomic, strong) YQStatusCellBottomView *bottomView;
@property (nonatomic, strong) YQReweetedStatusView *reweetedStatusView;
@property (nonatomic, strong)  MASConstraint *bottomConstraints;
@end
@implementation YQStatusCell
- (void)setStatus:(YQStatus*)status
{
    _status = status;
    self.originalView.originalStatus = status;
    [self.bottomConstraints uninstall];
    if (status.retweeted_status) {
        self.reweetedStatusView.retweetedStatus = status.retweeted_status;
        self.reweetedStatusView.hidden = NO;
       [self.bottomView updateConstraints:^(MASConstraintMaker *make) {
           self.bottomConstraints = make.top.equalTo(self.reweetedStatusView.bottom);
       }];
    }else{
        self.reweetedStatusView.hidden = YES;
        [self.bottomView updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstraints = make.top.equalTo(self.originalView.bottom);
        }];
    }
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self setupUI];
    return self;
}
- (void)setupUI{
    [self.contentView addSubview:self.originalView];
    [self.contentView addSubview:self.reweetedStatusView];
    [self.contentView addSubview:self.bottomView];
    [self.originalView makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.equalTo(self.contentView);
    }];
    [self.reweetedStatusView makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.equalTo(self.originalView);
        make.top.equalTo(self.originalView.bottom);
    }];
    [self.bottomView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
      self.bottomConstraints = make.top.equalTo(self.originalView.bottom).offset(StatusCellMargin);
        make.height.equalTo(40);
    }];
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bottomView);
        make.left.right.top.equalTo(self);
    }];
}
#pragma mark - 懒加载子控件
//原创微博
-(YQStatusOriginalView *)originalView{
    if (!_originalView) {
        _originalView = [[YQStatusOriginalView alloc]init];
    }
    return _originalView;
}
//转发微博
- (YQReweetedStatusView *)reweetedStatusView{
    if (!_reweetedStatusView) {
        _reweetedStatusView = [[YQReweetedStatusView alloc]init];
    }
    return _reweetedStatusView;
}
//微博底部
-(YQStatusCellBottomView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[YQStatusCellBottomView alloc]init];
    }
    return _bottomView;
}
@end
